package com.sc.nft.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.sc.nft.dao.UserCityServerCentreDao;
import com.sc.nft.dao.UserCollectionDao;
import com.sc.nft.dao.UserMarketValueDao;
import com.sc.nft.dao.UserWorkRoomDao;
import com.sc.nft.entity.ApplicationRequirement;
import com.sc.nft.entity.UserCityServerCentre;
import com.sc.nft.entity.UserInfo;
import com.sc.nft.entity.vo.ApplicationRequirementFactoryVO;
import com.sc.nft.enums.ApplicationRequirementEnum;
import com.sc.nft.service.ApplicationRequirementFactoryService;
import com.sc.nft.util.DecideUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

@Slf4j
@RequiredArgsConstructor
@Service
public class TeamHoldingCostApplicationRequirementFactoryServiceImpl implements ApplicationRequirementFactoryService {

    private final UserWorkRoomDao userWorkRoomDao;

    private final UserCollectionDao userCollectionDao;

    private final UserCityServerCentreDao userCityServerCentreDao;
    private final UserMarketValueDao userMarketValueDao;

    @Override
    public ApplicationRequirementFactoryVO applicationRequirement(UserInfo userInfo, ApplicationRequirement applicationRequirement,Integer type) {
//        Boolean urbanServiceCenter = Boolean.TRUE;
//        UserCityServerCentre userCityServerCentre = userCityServerCentreDao.selectByUserId(userInfo.getId());
//        if (BeanUtil.isEmpty(userCityServerCentre)) {
//            urbanServiceCenter = Boolean.FALSE;
//        }
//        // 获取用户持仓成本
//        BigDecimal theTotalPerformanceOfTheUserTeam = userCollectionDao.getTheTotalPerformanceOfTheUserTeam(userInfo.getId(), null, urbanServiceCenter);
//        if (ObjectUtil.isNull(theTotalPerformanceOfTheUserTeam)) {
//            theTotalPerformanceOfTheUserTeam=BigDecimal.ZERO;
//        }
//        // 2023-11-23 维护需求,增加熔炼为团队持仓成本在内.把数据加一起.
//        BigDecimal smeltingPosition = userMarketValueDao.getTheTotalPerformanceOfTheUserTeam(userInfo.getId(), null, urbanServiceCenter);
//        if (ObjectUtil.isNull(smeltingPosition)) {
//            smeltingPosition=BigDecimal.ZERO;
//        }
//        theTotalPerformanceOfTheUserTeam=theTotalPerformanceOfTheUserTeam.add(smeltingPosition);
//        ApplicationRequirementFactoryVO applicationRequirementFactoryVO = new ApplicationRequirementFactoryVO();
//        applicationRequirementFactoryVO.setKey(StrUtil.format("{}{}{}", applicationRequirement.getType().getDescription(), applicationRequirement.getJudgingCriteria(), applicationRequirement.valueConvert()));
//        applicationRequirementFactoryVO.setAskForValue(applicationRequirement.getValue());
//        applicationRequirementFactoryVO.setPracticalValue(Convert.toInt(theTotalPerformanceOfTheUserTeam));
//        // 根据compoundMode字段中的 > < >= <= = 五中 来判定是否满足条件
//        applicationRequirementFactoryVO.setSatisfy(DecideUtil.conditionalDecision(Convert.toInt(theTotalPerformanceOfTheUserTeam), applicationRequirement.getValue(), applicationRequirement.getJudgingCriteria()));
//        return applicationRequirementFactoryVO;
        return null;
    }

    @Override
    public Integer code() {
        return ApplicationRequirementEnum.TEAM_HOLDING_COST.getCode();
    }

}
